package by.bsu.scs.util.db;

import org.apache.log4j.Logger;
import org.hibernate.HibernateException;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.cfg.Configuration;

/**
 * @author Alexey Hursevich
 * @version 1.0
 * 
 * Responsible for Hibernate session creation using session factory.
 */
public class HibernateUtil {
	private static final SessionFactory sessionFactory;
	private static Logger logger = Logger.getLogger(HibernateUtil.class);
	static {
		try {
			sessionFactory = new Configuration().configure()
					.buildSessionFactory();
		} catch (HibernateException e) {
			logger.error(e);
			throw new ExceptionInInitializerError(e);
		}
	}

	public static Session openCurrentSession() {
		return sessionFactory.getCurrentSession();
	}
}